//
//  JMRegistViewMode.m
//  VoluntaryStar
//
//  Created by xiaorui on 15/9/1.
//  Copyright (c) 2015年 ios. All rights reserved.
//

#import "JMRegistViewMode.h"
#import "JMAppNetworkClient.h"
#import "JMUser.h"

@interface JMRegistViewMode()

@end

@implementation JMRegistViewMode

+ (void) fetchRegistMessageParametes:(NSDictionary *)dict  block:(ReturnBackMessage)block{
    [JMAppNetworkClient postRegistWithInfo:dict compelete:^(id data, NSError *error) {

        NSMutableDictionary *downDict = (NSMutableDictionary *)data;
        if([[downDict objectForKey:@"status"] integerValue] == 1){
            JMUser *user = [[JMUser alloc]init];
            user.message = [downDict objectForKey:@"message"];
            user.state = [NSString stringWithFormat:@"%@",[downDict objectForKey:@"status"]];
            user.token = [downDict objectForKey:@"token"];
            user.userId = [NSString stringWithFormat:@"%@",[downDict objectForKey:@"user"]];
            user.email = downDict[@"userinfo"][@"email"];
            user.lastTime = downDict[@"userinfo"][@"lasttime"];
            user.mobile = downDict[@"userinfo"][@"mobile"];
            user.regTime = downDict[@"userinfo"][@"regtime"];
            
            //获得Document的路径
            NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [documents stringByAppendingPathComponent:@"person.archiver"];//拓展名可以自己随便取
            [NSKeyedArchiver archiveRootObject:user toFile:path];
            block(data,error,user);
            
        }else{
            block(data,error,nil);
        }
    }];
}

@end
